
var bshowlog = false;
function printlog(log)
{
	if(bshowlog){
		if(window.console){
			console.log(log);
		}
	}
}

function showlog(log)
{
	if(bshowlog){
		alert(log);
	}
}

function prints(log)
{
	if(window.console){
		console.log(log);
	}
}

function max(arr){
	var j=0;
	for(var i=0;i<arr.length;i++){
		j=Math.max(j,arr[i]);
	}
	 return j;
}

function avg(arr){
	var j=0;
	for(var i=0;i<arr.length;i++){
		j=j+arr[i];
	}
	return Math.round(j/arr.length);
}	


function createZtree(servertitle,data) {
    var root = {
        name: servertitle +'  (' +data.length+')',
        title: '',
		open : true,
        children: []
    };
    var allData = {};
 
        var objinfo = data;
        for (var j = 0; j < objinfo.length; j++) {
            var info = JSON.parse(objinfo[j]);
            var path = info.path.split('/'); //路径
            var s = path[0];
            for (var k = 0; k < path.length; k++) {
                if (k == 0) {
                } else {
                    s += '/' + path[k];
                }

                var temp = {
                    name: path[k],
                    data: info.name,
                    children: []
                };
                if (!allData[s]) { //无此节点
                    allData[s] = temp;
                    if (k == 0) {
                        root.children.push(temp);
                        if (k == path.length - 1) {
                            temp.children.push({
                                name: info.title,
                                data: info.name,
								icon: closeimg,
                                children: []
                            })
                        }
                    } else {
						var silicepath = path.slice(0,1);
						for(var m = 1; m < k; m++){
							silicepath += '/';
							silicepath += path.slice(m, m+1);
						}
						//var silicepath = path.slice(0, k);
                        allData[silicepath].children.push(temp);
						if (k == path.length - 1) {
							temp.children.push({
								name: info.title,
								data: info.name,
								icon: closeimg,
								children: []
							});
						}
                    }
                } else { //增加叶子节点
                    if (k == path.length - 1) {
                        temp.name = info.title;
						temp.icon = closeimg;
                        allData[s].children.push(temp);
                    }
                }
            }
        }

	
	
	return root;
    //window.root = root;
}




function gettree(tempjson)
{
	if (!Array.isArray) {
  		Array.isArray = function(arg) {
    		return Object.prototype.toString.call(arg) === '[object Array]';
  		}
  	}
	if(Array.isArray(tempjson)){
		var temparr = new Array();
		for(var i=0; i<tempjson.length;i++)
		{
			var isaudio = false;
			for (var j in tempjson[i]){
				if(j=="对讲通道"){
					isaudio=true
					break;
				}
			}
			if(isaudio){
				continue;
			}
			temparr.push(gettree(tempjson[i]))
		}
		return temparr;
		 
	}
	else
	{
		for (var j in tempjson){
			if(Array.isArray(tempjson[j])){
				var obj = gettree(tempjson[j])
				return {'name':j,'children':obj};
			}
			else{
				var isaudio = (tempjson['isAudioIn']||tempjson['isAudioOut'])?true:false;
				if(isaudio)
				{
					//arraudio.push({'name':tempjson['title'],'data':tempjson['name'],'isAudioOut':tempjson['isAudioOut'],'isAudioIn':tempjson['isAudioIn']});
				}
				return {'name':tempjson['title'],'icon':closeimg, 'data':tempjson['name'],'devid':tempjson['devid'],'chnlid':tempjson['chnlid'],'isaudio':isaudio,'isrecording':false};
			}
		}
	}
	
}

function adjustjsontree(zTreeNodes)
{
	if (!Array.isArray) {
  		Array.isArray = function(arg) {
    		return Object.prototype.toString.call(arg) === '[object Array]';
  		}
  	}
	if(Array.isArray(zTreeNodes)){
		for(var i=0; i<zTreeNodes.length;i++)
		{
			if(zTreeNodes[i]['children'] && zTreeNodes[i]['name']!="对讲通道")
			{
				zTreeNodes[i]['open']=true;
			}
		} 
	}
	return zTreeNodes;
}

function isJson(obj)
{
var isjson = typeof(obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && !obj.length; 
return isjson;
}

function getCookie(name){
 var arg = name + "=";
 var alen = arg.length;
 var clen = document.cookie.length;
 var i = 0;
 while (i < clen){
 var j = i + alen;
 if(document.cookie.substring(i, j) == arg)
 return getCookieVal(j);
 i = document.cookie.indexOf(" ", i) + 1;
 if(i == 0) break;
 }
 return null;
}

function setCookie(name,value){
 var argv = setCookie.arguments;
 var argc = setCookie.arguments.length;
 var expires = (argc > 2) ? argv[2] : null;
 var path = (argc > 3) ? argv[3] : null;
 var domain = (argc > 4) ? argv[4] : null;
 var secure = (argc > 5) ? argv[5] : false;
 document.cookie = name + "=" + escape (value) +
 ((expires == null) ? "" : ("; expires=" + expires.toUTCString())) +
 ((path == null) ? "" : ("; path=" + path)) +
 ((domain == null) ? "" : ("; domain=" + domain)) +
 ((secure == true) ? "; secure" : "");
}

function getCookieVal(offset){
 var endstr = document.cookie.indexOf (";", offset); 
 if (endstr == -1) 
 endstr = document.cookie.length; 
 return unescape(document.cookie.substring(offset, endstr)); 
}

function GetfolderPath()
{
	var js=document.scripts;
	js=js[js.length-1].src.substring(0,js[js.length-1].src.lastIndexOf("/"));
	// js=js.substring(js.lastIndexOf(":")-1,js.lastIndexOf("/")+1)
	js=js.substring(0,js.lastIndexOf("/"))
	js = unescape(js);

	var i = js.indexOf("file:///");
	if(i==0)
	{
		js = js.substring(8);
	}
	return js;
}

function GetHttpPath()
{
	var js=document.scripts;
	js=js[js.length-1].src.substring(0,js[js.length-1].src.lastIndexOf("/"));
	// js=js.substring(js.lastIndexOf(":")-1,js.lastIndexOf("/")+1)
	js=js.substring(0,js.lastIndexOf("/"))
	js=js.substring(0,js.lastIndexOf("/"))
	js = unescape(js);
	return js;
	if(js.indexOf("http://")>=0)
	{
		return js;
	}
	else
	{
		return "http://192.168.60.242:";
	}
	
}


function GetHttpIP()
{
	var js=document.scripts;
	js=js[js.length-1].src.substring(0,js[js.length-1].src.lastIndexOf("/"));
	// js=js.substring(js.lastIndexOf(":")-1,js.lastIndexOf("/")+1)
	var ip =js.substring(0,js.indexOf(":"))
	var port=js.substring(js.indexOf(":"))
	port = port.substring(port.indexOf("/"))
	ip = ip+port;
	return ip;
}


function stringParseDate(str)
{
	str=str.replace(/-/g,"/");
	var strs= new Array(); //定义一数组 
	strs=str.split("."); //字符分割 
	var tmp=new Date(strs[0]);
	if(!tmp || isNaN(tmp.getFullYear())) { 
		return "";
	}
	var date=Tostr(tmp.getFullYear()) +"-"+Tostr(tmp.getMonth()+1)+ "-"+Tostr(tmp.getDate()) + " " + Tostr(tmp.getHours()) + ":" + Tostr(tmp.getMinutes()) + ":" + Tostr(tmp.getSeconds());
	if(strs.length>1){
		date = date+"."+ Tostr2(parseInt(strs[1]));
	}
	else{
		date = date+".000";
	}
	return date;
	
}

function stringParseDateSip(str)
{
	str=str.replace(/-/g,"/");
	var tmp=new Date(str);
	
	var date=Tostr(tmp.getFullYear()) +"-"+Tostr(tmp.getMonth()+1)+ "-"+Tostr(tmp.getDate()) + "T" + Tostr(tmp.getHours()) + ":" + Tostr(tmp.getMinutes()) + ":" + Tostr(tmp.getSeconds());
	
	return date;
	
}

function Tostr2(i)
{

	if(i<10){
		return "00"+i;
	}
	else if(i<100){
		return "0"+i;
	}
	else if(i>=100)
		return (i+"").substring(0,3);
	else
		return "000"
}


function Tostr(i)
{

	return (i<10) ? "0"+i : i;
}

//2012-01-01 13:20:00.000
function GetDurationRecord(end, begin)
{
	var timebegin = (begin.slice(0,19)).replace(/-/g,"/");
	timebegin = timebegin.replace(/T/g," ");
	var dbegin =new Date(timebegin);
	var timeend = (end.slice(0,19)).replace(/-/g,"/");
	timeend = timeend.replace(/T/g," ");
	var dend =new Date(timeend);
	var dur = (dend.getTime()-dbegin.getTime())/1000;
	dur = Math.floor(dur) *1000;
	return dur;

}

function GetDueString(_dur)
{
	var dur = _dur/1000;
	var str = Tostr(Math.floor(dur/3600))+":"+Tostr(Math.floor((dur%3600)/60))+":"+Tostr(Math.floor(dur%60));
	return str;
}



function GetMaxdtime(strspeed)
{
	var fspeed = 1.0;
	var speed = strspeed.match(/\d+/g);
	if(speed.length ==1){
		fspeed = parseInt(speed[0]);
	}
	return fspeed;
}

/*fileQuery是指input type为file的对象，在事件中使用this来替代，fakepath， 
比如:obj.onChange=function(){ 
var file_img=document.getElementById("img"); 
getPath(file_img,this,transImg); 
} 
transImg是解决IE左上角图标的那张透明图片的路径;*/ 
function getrealpath(obj,fileQuery,transImg){ 
	if(window.navigator.userAgent.indexOf("MSIE")>=1){ 
		obj.select(); 
		var path=document.selection.createRange().text; 
		if(obj.removeAttribute){
			obj.removeAttribute("src"); 
			obj.setAttribute("src",transImg); 
		}
		if(obj.style && obj.style.filter){
			obj.style.filter=   
			"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path+"', sizingMethod='scale');";  
			return obj.attr('value');
		}
		return path;
	} 
	else{ 
		var file =fileQuery.files[0];  
		var reader = new FileReader();  
		reader.onload = function(e){ 
			obj.setAttribute("src",e.target.result) 
		} 
		reader.readAsDataURL(file);
	}

}

/*
function getrealpath(obj){
	if (obj) {
		if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
			obj.select();
			return document.selection.createRange().text;
		}
		else if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
			if (obj.files) {
				return obj.files.item(0).getAsDataURL();
			}
			var path = window.URL.createObjectURL(f.files[0]);;
			path = obj.files.item(0).getAsDataURL();
			return obj.attr('value');
		}

		var path = obj.files.item(0).getAsDataURL();
		return obj.attr('value');
	}
}
*/

var NPPLAYER_NAME = "";

function readFileJSON(){ 
	var result = "";
	jQuery.ajax({
		url: GetHttpPath()+"/setup/pva-plugins.json",
		data: {},
		cache: false,
		type: "GET",
		timeout: 1000,
		async: false,
		success: function(res) {
			if (res.length !== 0) {
				if (typeof res === "string") {
					result = res;
					res = JSON.parse(res);
					NPPLAYER_NAME = res.name + " " + res.specialversion + " " + res.version + res.extname
					//prints("readFileJSON = "+result);
				}
				if (typeof res === "object") {
					result = JSON.stringify(res) ;
					NPPLAYER_NAME = res.name + " " + res.specialversion + " " + res.version + res.extname
					//prints("readFileJSON = "+result);
				}
			} else {
				prints("请求播放插件JOSN出错！");
			}
		},
		error: function() {
			prints("网络异常");
		}
	});
	return result;
} 

function downloadvideplayer()
{
	
	window.open(GetHttpPath()+"/setup/" + NPPLAYER_NAME,"downloadFrame");
	//window.open('"setup/"+NPPLAYER_NAME')
	jQuery.ajax({
		url: GetHttpPath()+"/setup/"+NPPLAYER_NAME,
        type: "POST",
        dataType:"jsonp",
		success: function(result) {
			prints("下载完成");
		},
		error: function() {
			prints("网络异常");
		}
	});
}

function InitMenu(ratio)
{
	var param ={
		"id":1,//整个菜单的ID，用于控制菜单的显示、隐藏、插入、删除等
		"text":"菜单",
		//"width":130,
		//"itemheight":25,
		//"iconwidth":25,
		"submenu":
		[
			{
				"id"      : 14,
				"text"    : "设置比例",
				"submenu" :
				[
					{
						"id"      : 141,
						"text"    : "原始",
						"check"   : ((ratio==1)?true:false)
					},
					{
						"id"      : 142,
						"text"    : "拉伸",
						"check"   : ((ratio==2)?true:false)
					},
					{
						"id"      : 143,
						"text"    : "4:3",
						"check"   : ((ratio==3)?true:false)
					},
					{
						"id"      : 144,
						"text"    : "16:9",
						"check"   : ((ratio==4)?true:false)
					},
					{
						"id"      : 145,
						"text"    : "16:10",
						"check"   : ((ratio==5)?true:false)
					}
				]
			}
		]
	};	
	param = JSON.stringify(param);
	return param;
}

function GetCheckRatio(nID)
{
	var param =[
		{
			"id"      : 141,
			"text"    : "原始",
			"check"   : ((nID==141)?true:false)
		},
		{
			"id"      : 142,
			"text"    : "拉伸",
			"check"   : ((nID==142)?true:false)
		},
		{
			"id"      : 143,
			"text"    : "4:3",
			"check"   : ((nID==143)?true:false)
		},
		{
			"id"      : 144,
			"text"    : "16:9",
			"check"   : ((nID==144)?true:false)
		},
		{
			"id"      : 145,
			"text"    : "16:10",
			"check"   : ((nID==145)?true:false)
		}
	];
	param = JSON.stringify(param);
	return param;
}

function GetVideoMenu(streamType, displayMode,audio,audiomode, bwatermenu)
////文件0、实时流1、录像2、PFS3、国标实时流4、国标录像5、RTSP6；
{
	if(!displayMode){
		displayMode=0;
	}
	if(!audio){
		audio = "";
	}

	var text = "";
	switch (streamType)
	{
	case 0:
		text = "关闭本地文件";
		break;
	case 1:
	case 8:
		text = "关闭实时流";
		break;
	case 2:
	case 9:
		text = "关闭录像";
		break;
	case 3:
		text = "关闭PFS文件";
		break;
	case 4:
		text = "关闭国标实时流";
		break;
	case 5:
		text = "关闭国标录像";
		break;
	case 6:
		text = "关闭RTSP流";
		break;
	case 7:
		text = "关闭RTSP录像";
		break;
	case 10:
		text = "关闭RTMP流";
		break;
	case 11:
		text = "关闭HLS流";
		break;
	case 12:
	    text = "关闭rofs流";
	    break;
	case 13:
	    text = "关闭rofs录像";
	    break;
	case 14:
	    text = "关闭pau流";
	    break;
	case 15:
	    text = "关闭pau录像";
	    break;
	case 16:
	    text = "关闭深网PVG";
	    break;
	case 17:
	    text = "关闭深网RTSP";
	    break;

	default:
	    break;
	}

	var param =[
		// {
		// 	"id"      : 17,
		// 	"text"    : "语音对讲",
		// 	"gray"	  : (((streamType==1||streamType==4||streamType==8)&&audio!="")?false:true),
		// 	"check"   : ((audiomode==3)?true:false)
		// 	// "submenu" :[{
		// 	// 	"id"      : 171,
		// 	// 	"text"    : "监听",
		// 	// 	"check"   : ((audiomode==1)?true:false)
		// 	// },
		// 	// {
		// 	// 	"id"      : 172,
		// 	// 	"text"    : "喊话",
		// 	// 	"check"   : ((audiomode==2)?true:false)
		// 	// },
		// 	// {
		// 	// 	"id"      : 173,
		// 	// 	"text"    : "对讲",
		// 	// 	"check"   : ((audiomode==3)?true:false)
		// 	// }]
		// },
		{
			"id"      : 13,
			"text"    : "3D云台",
			"gray"	  : (((streamType==1||streamType==4||streamType==8 ||streamType==14)&&displayMode==0)?false:true)
		},
		{
			"id"      : 12,
			"text"    : "窗口云台",
			"gray"    : ((streamType==1 ||streamType==4 ||streamType==8 ||streamType==14)?false:true)
		},
		{
			"id"      : 11,
			"text"    : "数字放大",
			"gray"	  : (displayMode==0?false:true)
		},
		{
			"id"      : 18,
			"text"    : "抓图",
		},
		{
			"id"      : 16,
			"text"    : "添加图像",
			"gray"	  : (displayMode==0?true:false)
		},
		{
			"id"      : 21,
			"text"    : "增加水印",
			"gray"	  : !bwatermenu
		},
		{
			"id"      : 30,
			"text"    : "开始录制",
			"gray"	  : ((streamType==1||streamType==12||streamType==8||streamType==6)?false:true)
		},
		{
			"id"      : 31,
			"text"    : "实时回放",
			"gray"	  : ((streamType==1||streamType==8)?false:true),
			"submenu" :[
				{
					"id"      : 311,
					"text"    : "实时预录",
					"check"   : false
				},
				{
					"id"      : 312,
					"text"    : "开启回放",
					"gray"    : true
				}
			]
		},
		{ 
			"id"      : 101,
			"type"    : 1
		},
		{ 
			"id"      : 10,
			"text"    : text
		},
		{ 
			"id"      : 20,
			"text"    : "关闭所有视频"
		},
		{
			"id"      : 40,
			"text"    : "反向播放",
			"gray"	  : ((streamType==13 || streamType==2  || streamType==9 )?false:true)
		}
		
	];	
	param = JSON.stringify(param);
	return param;
}



function GetVideotype(streamType)
{
	var text = "";
	switch (streamType)
	{
	case 0:
		text = "本地文件";
		break;
	case 1:
		text = "PVG实时流";
		break;
	case 2:
		text = "PVG录像";
		break;
	case 3:
		text = "PFS文件";
		break;
	case 4:
		text = "SIP实时流";
		break;
	case 5:
		text = "SIP录像";
		break;
	case 6:
		text = "RTSP实时流";
		break;
	case 7:
		text = "RTSP录像";
		break;
	case 8:
		text = "PVG+实时流";
		break;
	case 9:
		text = "PVG+录像";
		break;
	case 10:
		text = "RTMP实时流";
		break;
	case 11:
		text = "HLS录像";
		break;
	case 12:
		text = "ROFS实时流";
		break;
	case 13:
		text = "ROFS录像";
		break;
	case 14:
		text = "PAU实时流";
		break;
	case 15:
		text = "PAU录像";
		break;
	case 16:
		text = "深网PVG";
		break;
	case 17:
		text = "深网RTSP";
		break;
	default:
	    text = "无视频";
		break;
	}
	return text;
}


function InitToolbarBottom()
{

	var jsonTool = {
				"type": "panel",
				"style": "left-bottom",
				"key": 1,
				"x": "0",
				"y": "0",
				"dx":"5",
				"width": "100%",
				"height": "25px",
				"backColor": "0x242424",
				"transparent": "0.9", 
				"animateTime": "500",  //毫秒值
				"show": false,
				"items": [{
					"type": "button",
					"style": "left-top",
					"key": 11,
					"show": true,
					"x": "0",
					"y": "0",
					"width": "40px",
					"height": "100%",
					"backColor": "0xffc800",
					"text": "实时",
					"textColor": "0x000000",
					"font": "宋体",
					"fontSize": 12,
					"tooltip": "实时",
					"enable":true,
					"hoverCursor":"hand",
					"function": ""

				}, {
					"type": "button",
					"style": "left-top",
					"key": 12,
					"show": true,
					"x": "40",
					"y": "0",
					"width": "40px",
					"height": "100%",
					"backColor": "0x242424",
					"text": "历史",
					"textColor": "0xffffff",
					"font": "宋体",
					"fontSize": 12,
					"tooltip": "录像",
					"enable":true,
					"hoverCursor":"hand",
					"function": "ToolbarPlayRecord"

				},{
					"type": "button",
					"style": "left-top",
					"key": 111,
					"show": true,
					"x": "0",
					"y": "0",
					"width": "40px",
					"height": "100%",
					"backColor": "0x242424",
					"text": "实时",
					"textColor": "0xffffff",
					"font": "宋体",
					"fontSize": 12,
					"tooltip": "实时",
					"enable":true,
					"hoverCursor":"hand",
					"function": "ToolbarPlayStream"
				}, {
					"type": "button",
					"style": "left-top",
					"key": 121,
					"show": true,
					"x": "40",
					"y": "0",
					"width": "40px",
					"height": "100%",
					"backColor": "0xffc800",
					"text": "历史",
					"textColor": "0x000000",
					"font": "宋体",
					"fontSize": 12,
					"tooltip": "录像",
					"enable":true,
					"hoverCursor":"hand",
					"function": ""

				}, {
					"type": "button",
					"style": "left-top",
					"key": 112,
					"show": false,
					"x": "0",
					"y": "0",
					"width": "40px",
					"height": "100%",
					"backColor": "0xffc800",
					"text": "文件",
					"textColor": "0x000000",
					"font": "宋体",
					"fontSize": 12,
					"tooltip": "文件",
					"enable":true,
					"hoverCursor":"hand",
					"function": ""
				}, {
					"type": "button",
					"style": "left-top",
					"key": 122,
					"show": true,
					"x": "40",
					"y": "0",
					"width": "40px",
					"height": "100%",
					"backColor": "0x242424",
					"text": "片段",
					"textColor": "0xffffff",
					"font": "宋体",
					"fontSize": 12,
					"tooltip": "片段",
					"enable":true,
					"hoverCursor":"hand",
					"function": "ToolbarPlayRange"

				},{
					"type": "button",
					"style": "left-top",
					"key": 113,
					"show": false,
					"x": "0",
					"y": "0",
					"width": "40px",
					"height": "100%",
					"backColor": "0x242424",
					"text": "文件",
					"textColor": "0xffffff",
					"font": "宋体",
					"fontSize": 12,
					"tooltip": "文件",
					"enable":true,
					"hoverCursor":"hand",
					"function": "ToolbarPlayRangeCancel"
				}, {
					"type": "button",
					"style": "left-top",
					"key": 123,
					"show": true,
					"x": "40",
					"y": "0",
					"width": "40px",
					"height": "100%",
					"backColor": "0xffc800",
					"text": "片段",
					"textColor": "0x000000",
					"font": "宋体",
					"fontSize": 12,
					"tooltip": "片段",
					"enable":true,
					"hoverCursor":"hand",
					"function": "ToolbarPlayRange"

				},{
					"type": "button",
					"style": "left-top",
					"key": 13,
					"show": true,
					"left":20,
					"x": "100",
					"y": "2",
					"width": "80px",
					"height": "22px",
					"backColor": "0x3400ff",
					"text": "手动报警",
					"textColor": "0xffffff",
					"font": "宋体",
					"fontSize": 12,
					"tooltip": "",
					"enable":true,
					"hoverCursor":"hand",
					"function": "ToolbarAlaram"
				}, {
					"type": "button",
					"style": "left-top",
					"key": 14,
					"show": false,
					"x": "100",
					"y": "0",
					"left":10,
					"width": "20px",
					"height": "100%",
					"backColor": "0x242424",
					"picture": {
						"normal": "slow_normal.png",
						"hover": "slow_hover.png",
						"keydown": "slow_hover.png",
						"disabled": "slow_normal.png"
					},
					"tooltip": "慢放",
					"enable":true,
					"function": "ToolbarPlaySlow"
				}, {
					"type": "button",
					"style": "left-top",
					"key": 15,
					"show": false,
					"x": "117",
					"y": "0",
					"width": "20px",
					"height": "100%",
					"backColor": "0x242424",
					"picture": {
						"normal": "pause_normal.png",
						"hover": "pause_hover.png",
						"keydown": "pause_hover.png",
						"disabled": "pause_normal.png"
					},
					"tooltip": "暂停",
					"enable":true,
					"function": "ToolbarPauseTrue"
				},{
					"type": "button",
					"style": "left-top",
					"key": 151,
					"show": false,
					"x": "117",
					"y": "0",
					"width": "20px",
					"height": "100%",
					"backColor": "0x242424",
					"picture": {
						"normal": "play_normal.png",
						"hover": "play_hover.png",
						"keydown": "play_hover.png",
						"disabled": "play_normal.png"
					},
					"tooltip": "播放",
					"enable":true,
					"function": "ToolbarPauseFalse"
				}, {
					"type": "button",
					"style": "left-top",
					"key": 16,
					"show": false,
					"x": "134",
					"y": "0",
					"width": "20px",
					"height": "100%",
					"backColor": "0x242424",
					"picture": {
						"normal": "step_normal.png",
						"hover": "step_hover.png",
						"keydown": "step_hover.png",
						"disabled": "step_normal.png"
					},
					"tooltip": "单帧播放",
					"enable":true,
					"function": "ToolbarPlayStep"
				},  {
					"type": "button",
					"style": "left-top",
					"key": 17,
					"show": false,
					"x": "151",
					"y": "0",
					"width": "20px",
					"height": "100%",
					"backColor": "0x242424",
					"picture": {
						"normal": "fast_normal.png",
						"hover": "fast_hover.png",
						"keydown": "fast_hover.png",
						"disabled": "fast_normal.png"
					},
					"tooltip": "快放",
					"enable":true,
					"function": "ToolbarPlayFast"
				},{
					"type": "static",
					"style": "left-top",
					"key": 18,
					"show": false,
					"backColor": "0x242424",
					"x": "168",
					"y": "4",
					"left":5,
					"width": "40px",
					"height": "100%",
					"text": "x1",
					"textColor": "0xffffff",
					"font": "宋体",
					"fontSize": 14
				},{
					"type": "static",
					"style": "right-top",
					"key": 101,
					"show": true,
					"backColor": "0x242424",
					"x": "0",
					"y": "5",
					"width": "60px",
					"height": "100%",
					"text": "0:0:0",
					"textColor": "0xffffff",
					"font": "宋体",
					"fontSize": 14
				},{
					"type": "static",
					"style": "right-top",
					"key": 102,
					"show": true,
					"backColor": "0x242424",
					"x": "0",
					"y": "5",
					"width": "60px",
					"height": "100%",
					"text": "0:0:0",
					"textColor": "0xffffff",
					"font": "宋体",
					"fontSize": 14
				},{
					"type": "process",
					"style": "right-top",
					"key": 19,
					"show": false,
					"x": "132",
					"y": "0",
					"dleft":"5",
					"left":20,
					"adjustwidth":true,
					"width": "100%",
					"height": "100%",
					"backColor": "0x242424",
					//"hoverCursor":"hand",
					"thumbHoverCursor":"hand",
					"picture": {
						"backGround": "progessbar-bg.png",
						"backGroundHover": "progressbar.png",
						"playThumb": "thumb_hover.png",
						"playThumbHover": "thumb_hover.png",
						"startFlag": "imagejude-before.png",
						"startFlagHover": "imagejude-beforehover.png",
						"endFlag": "imagejude-after.png",
						"endFlagHover": "imagejude-afterhover.png"
					},
					"enable":true,
					"funPosChange": "ToolbarPosChange",
					"funRangeChange": "ToolbarRangeChange",
					"funMouseOnChannel": "ToolbarMouseOnChannal"
				}]
			};
	//jsonTool = JSON.stringify(jsonTool);
	return jsonTool;
			
}

function InitToolbarTop()
{
	var jsonTool= {
				"type": "panel",
				"style": "left-top",
				"key": 2,
				"x": "0",
				"y": "0",
				"dx":"5",
				"dl":"5",
				"dr":"5",
				"width": "100%",
				"height": "25px",
				//"transparent": "0.6",
				"animateTime": "1000",
				"show": false,
				"backColor": "0x242424",

				"items": [{
					"type": "button",
					"style": "right-top",
					"key": 21,
					"show": true,
					"x": "10",
					"y": "0",
					"width": "30px",
					"height": "100%",
					"backColor": "0x242424",

					"picture": {
						"normal": "close_normal.png",
						"hover": "close_hover.png",
						"keydown": "close_hover.png",
						"disabled": "close_normal.png",
					},
					"text": "",
					"textColor": "",
					"font": "宋体",
					"fontSize": 12,
					"tooltip": "关闭",
					"enable":true,
					"function": "ToolbarStop"

				},{
					"type": "button",
					"style": "right-top",
					"key": 221,
					"show": true,
					"x": "0",
					"y": "0",
					"width": "30px",
					"height": "100%",
					"backColor": "0x242424",

					"picture": {
						"normal": "remove_normal.png",
						"hover": "remove_hover.png",
						"keydown": "remove_hover.png",
						"disabled": "remove_normal.png",
					},
					"text": "",
					"textColor": "",
					"font": "宋体",
					"fontSize": 12,
					"tooltip": "删除绘图",
					"enable":true,
					"function": "ToolbarRemoveDraw"

				},{
					"type": "button",
					"style": "right-top",
					"key": 22,
					"show": true,
					"x": "30",
					"y": "0",
					"width": "30px",
					"height": "100%",
					"backColor": "0x242424",

					"picture": {
						"normal": "draw_normal.png",
						"hover": "draw_hover.png",
						"keydown": "draw_hover.png",
						"disabled": "draw_normal.png",
					},
					"text": "",
					"textColor": "",
					"font": "宋体",
					"fontSize": 12,
					"tooltip": "绘图",
					"enable":true,
					"function": "ToolbarStreamDraw",
					
					"leftOrRight":true,     //菜单的位置，true为左，false为右			            "upOrDown":false,		//菜单的位置，true为上，false为下
		            "menuList": {			// menuList属性代表此类型的控件为菜单
			            "width": "100",		//menu宽度
			            "items": [{		// items 属性为工具条上的菜单元素数组
			            	"text": "直线箭头",
				       		"menuid": 1,   	//菜单索引
				        	"function": "ToolbarMenu" //索引为0的菜单的回调函数名字
				           
			            },{
			            	"text": "矩形",
				            "menuid": 2,
				            "function": "ToolbarMenu"
			            },{
			            	"text": "多边形",
				            "menuid": 3,
				            "function": "ToolbarMenu"
			            },{
			            	"text": "单线",
				            "menuid": 4,
				            "function": "ToolbarMenu"
			            },{
			            	"text": "双线",
				            "menuid": 5,
				            "function": "ToolbarMenu"
			            }]
		            },


				},{
					"type": "button",
					"style": "right-top",
					"key": 23,
					"show": true,
					"x": "60",
					"y": "0",
					"width": "30px",
					"height": "100%",
					"backColor": "0x242424",

					"picture": {
						"normal": "catch_normal.png",
						"hover": "catch_hover.png",
						"keydown": "catch_hover.png",
						"disabled": "catch_normal.png",
					},
					"text": "",
					"textColor": "",
					"font": "宋体",
					"fontSize": 12,
					"tooltip": "抓图",
					"enable":true,
					"function": "ToolbarCapture"

				},{
					"type": "button",
					"style": "right-top",
					"key": 28,
					"show": true,
					"x": "90",
					"y": "0",
					"width": "30px",
					"height": "100%",
					"backColor": "0x242424",

					"picture": {
						"normal": "catch_n_normal.png",
						"hover": "catch_n_hover.png",
						"keydown": "catch_n_hover.png",
						"disabled": "catch_n_normal.png",
					},
					"text": "",
					"textColor": "",
					"font": "宋体",
					"fontSize": 12,
					"tooltip": "连拍",
					"enable":true,
					"function": "ToolbarContinuousCapture"

				},{
					"type": "button",
					"style": "right-top",
					"key": 27,
					"show": true,
					"x": "120",
					"y": "0",
					"width": "30px",
					"height": "100%",
					"backColor": "0x242424",

					"picture": {
						"normal": "sound_normal.png",
						"hover": "sound_hover.png",
						"keydown": "sound_hover.png",
						"disabled": "sound_normal.png",
					},
					"text": "",
					"textColor": "",
					"font": "宋体",
					"fontSize": 12,
					"tooltip": "声音",
					"enable":true,
					"function": "ToolbarSoundTrue"

				},{
					"type": "button",
					"style": "right-top",
					"key": 271,
					"show": false,
					"x": "120",
					"y": "0",
					"width": "30px",
					"height": "100%",
					"backColor": "0x242424",

					"picture": {
						"normal": "sound_0_normal.png",
						"hover": "sound_0_hover.png",
						"keydown": "sound_0_hover.png",
						"disabled": "sound_0_normal.png",
					},
					"text": "",
					"textColor": "",
					"font": "宋体",
					"fontSize": 12,
					"tooltip": "静音",
					"enable":true,
					"function": "ToolbarSoundFalse"
				},{
					"type": "button",
					"style": "right-top",
					"key": 29,
					"show": true,
					"x": "180",
					"y": "0",
					"width": "30px",
					"height": "100%",
					"backColor": "0x242424",

					"picture": {
						"normal": "ptz_normal.png",
						"hover": "ptz_hover.png",
						"keydown": "ptz_hover.png",
						"disabled": "ptz_normal.png",
					},
					"text": "",
					"textColor": "",
					"font": "宋体",
					"fontSize": 12,
					"tooltip": "云台",
					"enable":true,
					"function": "ToolbarPTZ"

				},{
					"type": "static",
					"style": "left-top",
					"key": 25,
					"show": true,
		      		"backColor": "0x242424",
					"x": "10",
					"y": "4",
					"width": "70px",
					"height": "100%",
					"text": "无视频",
					"textColor": "0xffffff",
					"tooltip": "无视频",//提示框，无此项或为""，则不显示，
					                    //如创建后更改了text文本内容，提示随text改变
					                    //有提示框时，文本内容过长会自动截取
					"font": "宋体",
					"fontSize": 14
				},{
					"type": "static",
					"style": "left-top",
					"key": 26,
					"show": true,
		      		"backColor": "0x242424",
					"x": "80",
					"y": "4",
					"width": "120px",
					"height": "100%",
					"text": "0bps",
					"textColor": "0xffffff",
					"font": "宋体",
					"fontSize":14
				}]
			};
	//jsonTool = JSON.stringify(jsonTool);
	return jsonTool;
}


function isFile(streamType)
{
	if(streamType==1 || streamType==4 || streamType==6
		|| streamType==8 || streamType==10 || streamType==12 
		|| streamType == 14 || streamType==16 || streamType==17){
		return false;
	}
	return true;
}

function isRange(streamType)
{
	if(streamType==0||streamType==3){
		return true;
	}
	else
		return false;
}

function isStream(streamType)
{
	if(streamType==1 || streamType==4 || streamType==6
		|| streamType==8 || streamType==10 || streamType == 12
		|| streamType == 14 || streamType==16 || streamType == 17){
		return true;
	}
	return false;
}

function isRecord(streamType)
{
	if(streamType==2 || streamType==5 || streamType==9 
		|| streamType == 13 || streamType == 15){
		return true;
	}
	return false;
}

function GetVideToolbarBottomObjs(toolbarinfo, streamType, width, brange, bpause)
{
	if(!toolbarinfo)
		return;
	for(var i=0; i<toolbarinfo.length; i++){
		var info=toolbarinfo[i];
		if(info.key == 11){//实时中
			toolbarinfo[i].show = isStream(streamType);
		}
		else if(info.key == 12){//历史
			toolbarinfo[i].show = isStream(streamType);
		}
		else if(info.key == 111){//实时
			toolbarinfo[i].show = isRecord(streamType);
		}
		else if(info.key == 121){//历史中
			toolbarinfo[i].show = isRecord(streamType);
		}
		else if(info.key == 112){//文件中
			toolbarinfo[i].show = (isRange(streamType) && !brange);
		}
		else if(info.key == 122){//片段
			toolbarinfo[i].show = (isRange(streamType) && !brange);
		}
		else if(info.key == 113){//文件
			toolbarinfo[i].show = (isRange(streamType) && brange);
		}
		else if(info.key == 123){//片段中
			toolbarinfo[i].show = (isRange(streamType) && brange);
		}
		else if(info.key == 13){//实时警报
			toolbarinfo[i].show = isStream(streamType);
		}
		else if(info.key == 14){//慢放
			toolbarinfo[i].show = isFile(streamType);
		}
		else if(info.key == 15){//暂停
			toolbarinfo[i].show = isFile(streamType) && !bpause;
		}
		else if(info.key == 151){//恢复播放
			toolbarinfo[i].show = isFile(streamType) && bpause;
		}
		else if(info.key == 16){//单帧
			toolbarinfo[i].show = isFile(streamType);
		}
		else if(info.key == 17){//快放
			toolbarinfo[i].show = isFile(streamType);
		}
		else if(info.key == 18){//速度
			toolbarinfo[i].show = isFile(streamType);
		}
		else if(info.key == 19){//进度条
			toolbarinfo[i].show = isFile(streamType);
		}
		else if(info.key == 102){//播放时长
			toolbarinfo[i].show = isFile(streamType);
		}
		else if(info.key == 101){//总时长
			toolbarinfo[i].show = isFile(streamType);
		}
	}
	

	moveHideToolbarItem(toolbarinfo, width, false)

	return toolbarinfo;
}

function isdraw(streamType, displaymode, istrack)
{
	if(displaymode == 0)
		return false;
	if(istrack)
		return false;

	//if(streamType==1 || streamType==2 || streamType==8 || streamType==9 || streamType==12 || streamType==12 || streamType == 6)
	//	return true;
		return true;

}

function GetVideToolbarTopObjs(toolbarinfo, streamType, bsound, displaymode,istrack)
{
	if(!toolbarinfo)
		return;
	
	for(var i=0; i<toolbarinfo.length; i++){
		var info=toolbarinfo[i];
		if(info.key == 25){//视频
			toolbarinfo[i].show = true;
		}
		else if(info.key == 26){//速率
			toolbarinfo[i].show = true;
		}
		else if(info.key == 29){//云台
			toolbarinfo[i].show = isStream(streamType);
		}
		else if(info.key == 27){//声音
			toolbarinfo[i].show = !bsound;
		}
		else if(info.key == 271){//静音
			toolbarinfo[i].show = bsound;
		}
		else if(info.key == 28){//连拍
			toolbarinfo[i].show = true; 
		}
		else if(info.key == 23){//抓图
			toolbarinfo[i].show = true;
		}
		else if(info.key == 22){//绘图
			toolbarinfo[i].show = isdraw(streamType, displaymode,istrack);
		}
		else if(info.key == 221){//删除绘图
			toolbarinfo[i].show = isdraw(streamType, displaymode,istrack);
		}
		else if(info.key == 21){//关闭
			toolbarinfo[i].show = true;
		}
	}
	

	//moveHideToolbarItem(toolbarinfo, width, true)

	return toolbarinfo;
}


function moveHideToolbarItem(toolbarinfo, width, bright)
{
	var index = -1;
	var rx = 0;
	var rx1 = 0;
	var lx = 0;
	for(var i=0; i<toolbarinfo.length; i++){
		var info=toolbarinfo[i];
		if(info.show){
			if(info.style==="right-top")
			{
				if(info.left){
					rx += parseInt(info.left);
				}
				info.x = rx+"px";


				if(!info.adjustwidth)
				{
					rx += parseInt(info.width);
					if(rx1 === 0){
						rx1 = parseInt(info.width);
					}
				}
				else{
					index = i;
					rx += 15;
					toolbarinfo[i].width = "15px";
				}
			}
			else if(info.style==="left-top"){
				if(info.left){
					lx += info.left;
				}
				info.x = lx+"px";
				if(!info.adjustwidth)
				{
					lx += parseInt(info.width);
				}
				else{
					index = i;
					lx += 15;
					toolbarinfo[i].width = "15px";
				}
			}
			
		}
	}



	if(!bright){
		rx1 = 0;
	}

	if(width > lx+rx){
		if(index!=-1){
			var xx = width - rx - lx;
			if(xx > 10){
				var width = xx-10+15;
				toolbarinfo[index].width = width+"px";
			}	
		}
	}
	else if(width > lx+rx1){
		var xleft = width - lx;
		for(var i=0; i<toolbarinfo.length; i++){
			var info=toolbarinfo[i];
			if(info.show && info.style==="right-top"){
				if(parseInt(info.x) + parseInt(info.width) > xleft ){
					toolbarinfo[i].show = false;
				}
			}
		}
	}
	else
	{
		var bGetFirst = false;
		if(!bright){
			bGetFirst = true;
		}
		var xleft = width - rx1;
		for(var i=0; i<toolbarinfo.length; i++){
			var info=toolbarinfo[i];
			if(info.show){
				if(info.style==="right-top"){
					if(!bGetFirst){
						bGetFirst = true;
					}
					else{
						toolbarinfo[i].show = false;
					}
				}
				else if(info.style==="left-top"){
					if(parseInt(info.x) + parseInt(info.width) > xleft){
						toolbarinfo[i].show = false;
					}
				}
			}
		}

		
	}
}




function getRangeToolbarObjs(streamType, brange)
{
	var toolbarObjs = [
			{"key":112,//文件中
			"show":(isRange(streamType) && !brange),
			"enable":true,
			"status":0
			},{
			"key":122,//片段
			"show":(isRange(streamType) && !brange),
			"enable":true,
			"status":0
			},{
			"key":113,//文件
			"show":(isRange(streamType) && brange),
			"enable":true,
			"status":0
			},{
			"key":123,//片段中
			"show":(isRange(streamType) && brange),
			"enable":true,
			"status":0
			}];
	return toolbarObjs;
}


function GetPtzWebinfo()
{
	var dir = GetfolderPath();
	var info = {
		"url":dir+"/ptzweb.html", //网址  
		"center":true, //true,false  是否居中，如果center为false，则设置left,top,定位
		"left":0,  //单位像素
		"top":200, 
		"width":380,  //宽度
		"height":345,// 高度
		"alpha":0.2,// 透明度
		"resize":true,//可以拖动大小 
		"movingwithinpage":true, //页面内移动
		"modal":false, //模式粗航口
		"border":{  //边框
			"width":2, //粗细
			"color":0x00ff00ff  // RGB颜色
		}, 
		"title":{  //标题
			"text":"云台控制" ,
			"textcolor":0,
			"font":"微软雅黑",
			"fontsize":12,
			"color": 0x00F5F5DC,// RGB颜色,
			"height":30 ,
			"leftmargin":17
		}, 
		"closebtn":{  //关闭按钮
			"rightmargin":10,
			"show":true //是否显示按钮
		} , 
		"minbtn":{  //最小化按钮
			"rightmargin":10,
			"show":true, //是否显示按钮
			"restore":{ //点击后显示还原按钮，无此项时点击后隐藏dialog 
				"show":true, // 为false时，点击最小化后隐藏dialog
	  			"left":0,//百度比，范围0-100 最小化后在网页中为位置 0表示最上 100表示最下
				"top":100, //百度比，范围0-100 最小化后在网页中为位置 0表示最左 100表示最右
				"width":200  //宽度 单位像素
				//"height":30,// 高度 单位像素
	  			//"text" :"历史录像", //显示的标题 无此项是显示为 title的text
				//"font":"微软雅黑",
				//"fontsize":12,
				//"textcolor":0x00ff0000,
				//"color": 0x0000DC,// RGB颜色,
				//"height":30 ,
				//"leftmargin":17
			}

		} 
	}

	return JSON.stringify(info);

}
